package com.yh.ssm.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yh.ssm.dao.ProductMapper;
import com.yh.ssm.model.Page;
import com.yh.ssm.model.Product;
import com.yh.ssm.service.IProductService;

@Service("ips")
public class ProductServiceImpl implements IProductService {
	
    private static Logger logger = LogManager.getLogger(ProductServiceImpl.class);
    
    @Autowired
    private ProductMapper pm;

	@Override
	public Product find(Product product) {
		// TODO Auto-generated method stub
		
		return pm.find(product);
	}
/**
 * 商品信息增加
 */
	@Override
	public int save(Product product) {
		// TODO Auto-generated method stub
		logger.error("添加用户："+product);
	
		int i=pm.save(product);
		return i;
	}

	@Override
	public int del(Product product) {
		int i=pm.del(product);
		return i;

	}

	@Override
	public int edit(Product product) {
		int i=pm.edit(product);
		return i;
	

	}
/**
 * 分页模糊查询方法
 */
	@Override
	public Page getProduct(Map<String, Object> product) {
		// TODO Auto-generated method stub
		Page page =new Page();
		page.setResult(pm.getProduct(product));//查询的分页数据放在page数组中
		page.setPageSize(Integer.parseInt(String.valueOf(product.get("pageSize"))));//把分页的大小放入数组中
		page.setCurPageNum(Integer.parseInt(String.valueOf(product.get("pageNum"))));//把分页的当前也传入page中
		page.setTotalNum(pm.getCount(product));//查询符合条件的数据的总条数
		//计算总页数
		
		int pageTotal=page.getTotalNum()%page.getPageSize()==0?page.getTotalNum()/page.getPageSize():page.getTotalNum()/page.getPageSize()+1;
		page.setTotalPage(pageTotal);//把分页总条数放到page中
	
		return page;
	}

}
